package com.knife.file.api.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.knife.common.utils.Results;
import com.knife.file.app.KnifeStorageConfigService;
import com.knife.file.domain.entity.KnifeStorageConfig;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 文件存储配置模块controller
 *
 * @author： 76875
 * @date： 2022/4/7 星期四 11:49
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/{organizationId}/file/storage-config")
public class KnifeStorageConfigController {
    @Resource
    private KnifeStorageConfigService knifeStorageConfigService;

    /**
     * 保存文件存储配置
     *
     * @param knifeStorageConfig 配置
     * @return 配置
     */
    @PostMapping
    public ResponseEntity<KnifeStorageConfig> saveOrUpdateConfig(@PathVariable Long organizationId, @RequestBody KnifeStorageConfig knifeStorageConfig) {
        knifeStorageConfig.setTenantId(organizationId);
        return Results.success(knifeStorageConfigService.saveOrUpdateConfig(knifeStorageConfig));
    }

    /**
     * 查询文件存储配置
     *
     * @param knifeStorageConfigPage 分页
     * @param knifeStorageConfig     存储配置
     * @return 分页
     */
    @GetMapping
    public ResponseEntity<Page<KnifeStorageConfig>> selectKnifeStorageConfigPage(
            @PathVariable Long organizationId,
            Page<KnifeStorageConfig> knifeStorageConfigPage,
            KnifeStorageConfig knifeStorageConfig) {
        knifeStorageConfig.setTenantId(organizationId);
        return Results.success(knifeStorageConfigService.selectKnifeStorageConfigPage(knifeStorageConfigPage, knifeStorageConfig));
    }

    /**
     * 删除文件存储配置
     *
     * @param knifeStorageConfig 存储配置
     * @return 配置
     */
    @DeleteMapping
    public ResponseEntity<KnifeStorageConfig> deleteConfig(@PathVariable Long organizationId, @RequestBody KnifeStorageConfig knifeStorageConfig) {
        knifeStorageConfig.setTenantId(organizationId);
        return Results.success(knifeStorageConfigService.deleteConfig(knifeStorageConfig));
    }
}
